define(["jquery", "dialog", "handlebars"], function ($, dailog, handlebars) {
    var uniqueInt = 0, types = function (obj) {
            var regex = /\[object\s+(\w+)\]/i, tt = Object.prototype.toString.call(obj), re = regex.exec(tt);
            return (re && re.length > 0) ? re[1].toLowerCase() : 'error';
        }, debug = function ($obj) {
            if (console && console.dir) {
                console.dir($obj);
            }
        }, logger = function (level) {
            var config = {
                DEBUG: 0,
                INFO: 1,
                WARN: 2,
                ERROR: 3,
                level: level,
                methodMap: {
                    0: 'debug',
                    1: 'info',
                    2: 'warn',
                    3: 'error'
                }
            };
            return function (level, obj) {
                if (config.level <= level) {
                    var method = config.methodMap[level];
                    if (dMode && typeof console !== 'undefined' && console[method]) {
                        console[method].call(console, obj);
                    }
                }
            };
        }, ajaxErrorHandler = {
            '400': function (obj, s) {
                projectLib.alert("\u8bf7\u68c0\u67e5\u60a8\u7684\u8f93\u5165\u662f\u5426\u6b63\u786e\uff0c\u6216\u8005\u53ef\u80fd\u7f51\u7edc\u51fa\u73b0\u4e86\u5f02\u5e38");
            },
            '401': function (obj, s) {
                projectLib.alert("\u60a8\u8fd8\u6ca1\u6709\u767b\u5f55\uff0c\u6216\u8005\u6ca1\u6709\u6743\u9650\u8bbf\u95ee\u8be5\u529f\u80fd");
            },
            '403': function (obj, s) {
                projectLib.alert('\u62b1\u6b49\uff0c\u60a8\u9700\u8981\u5148\u767b\u5f55\u6709\u6b64\u6743\u9650\u7684\u5e10\u53f7\u624d\u80fd\u4f7f\u7528\u8be5\u529f\u80fd');
            },
            '404': function (obj, s) {
                projectLib.alert("\u53ef\u80fd\u60a8\u9700\u8981\u5237\u65b0\u7f51\u9875\uff0c\u6240\u4f7f\u7528\u7684\u6570\u636e\u672a\u627e\u5230");
            },
            '409': function (obj, s) {
                projectLib.alert("\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u64cd\u4f5c\u65e0\u6cd5\u5b8c\u6210");
            },
            '500': function (obj, s) {
                projectLib.alert("\u7cfb\u7edf\u51fa\u9519\uff0c\u8bf7\u91cd\u8bd5");
            },
            '503': function (obj, s) {
                projectLib.alert("\u7cfb\u7edf\u51fa\u9519\uff0c\u8bf7\u91cd\u8bd5");
            },
            '0': function (obj, s) {
                projectLib.alert("\u6240\u8fde\u63a5\u7684\u7f51\u7ad9\u65e0\u54cd\u5e94\uff0c\u8bf7\u68c0\u67e5\u7f51\u7edc\u8fde\u63a5\u662f\u5426\u6b63\u5e38");
            }
        }, ajax = function (url, param, callback, method, contentType, options) {
            var requestParam;
            if (types(param) === "string") {
                requestParam = param;
            } else if (types(param) === "object") {
                requestParam = {};
                requestParam = $.extend({}, param, {
                    t: (new Date()).getTime()
                });
            }
            var errHandler = projectLib.param.ajaxDefaultErrorHandler;
            if (options && options.errHandler !== undefined) {
                errHandler = $.extend(errHandler, options.errHandler);
            }
            if (method === undefined) {
                method = 'GET';
            }
            var requestObj = {
                url: url,
                type: method,
                timeout: 80000,
                data: requestParam,
                dataType: "json"
            };
            if (contentType !== undefined) {
                requestObj.contentType = contentType;
            }
            var request = $.ajax(requestObj);
            request.done(function (msg) {
                if ($.isFunction(callback)) {
                    //msg = $.trim(msg);
                    callback.apply(this, [msg]);
                }
            });
            request.fail(function (jqXHR, textStatus) {
                var s = jqXHR.status;
                if (s in errHandler) {
                    errHandler[s].apply(this, [jqXHR, s]);
                } else {
                    projectLib.alert(url + " \u672a\u77e5\u9519\u8bef\u53d1\u751f");
                }
                if (options && options.retureWhatever) {
                    if ($.isFunction(callback)) {
                        callback.apply(this, ['']);
                    }
                }
            });
            return request;
        }, dialogDefaultParam = {
            dialogClass: 'no-close',
            minHeight: 170,
            minWidth: 270,
            width: 310,
            modal: true,
            autoOpen: false,
            show: {
                effect: "drop",
                duration: 500
            },
            hide: {
                effect: "blind",
                duration: 500
            },
            position: {my: "center", at: "center top+25%", of: window}
        }, dialogFactory = function (type, tt) {
            var tag = '-' + (new Date().getTime());
            type = type || 'common-alert', tt = tt || '\u4fe1\u606f';
            var idstr = 'i-' + type + tag;

            if (type == 'confirmmaje'){
                modal = '<div id="' + idstr + '"  title="" style="z-index:100000;overflow:hidden;"><div class="modal-header confirm-header padding0"><h3 class="dialog-confirm-title">请输入资产定制模型名称</h3></div><div class="modal-body padding0"></div><div class="modal-footer confirm-footer padding0"><button type="button" class="btn btn-yes" value="确认">确认</button><button class="btn btn-no" value="取消">取消</button></div></div>';
            }
            else if (type == 'protocol') {
                modal = '<div id="' + idstr + '"  title="" style="z-index:100000;overflow:hidden;"><div class="modal-header protocol-header"><h3 class="dialog-protocol-title">协议名称</h3><div class="dialog-protocol"></div><div class="dialog-cancel btn-no icon-close"><span class="path1"></span><span class="path2"></span><span class="path3"></span></div></div><div class="modal-body"></div><div class="modal-footer alert-footer"><button class="btn btn-yes">确定</button></div></div>';
            }
            else if (type == 'alert') {
                modal = '<div id="' + idstr + '"  title="" style="z-index:100000;overflow:hidden;"><div class="modal-header alert-header padding0"><h3 class="dialog-alert-title">警告</h3><div class="dialog-alert"></div><div class="dialog-cancel btn-no"></div></div><div class="modal-body padding0"></div><div class="modal-footer alert-footer padding0"><button class="btn btn-no btn-success">确定</button></div></div>';
            }
            else {
                modal = '<div id="' + idstr + '"  title="" style="z-index:100000;overflow:hidden;"><div class="modal-header confirm-header padding0"><h3 class="dialog-confirm-title">提示</h3></div><div class="modal-body padding0"></div><div class="modal-footer confirm-footer padding0"><button class="btn btn-no" value="取消">取消</button><button type="button" class="btn btn-yes" value="确认">确认</button></div></div>';
            }

            //projectLib.insertHidenEl(modal, 'info-container');
            var o = $(modal).attr('title', tt);
            var $btn = o.find('.modal-footer .btn-yes').click(function (event) {
                o.dialog('close');
            }), $bt = o.find('.btn-no').click(function (event) {
                o.dialog('close');
            }), $body = o.find('.modal-body'), $title = o.find('.modal-header h3');
            //$btn.html('\u786e\u8ba4');$bt.html('\u5426');
            return function (msg, callback, ops) {
                if (callback && types(callback) === 'function') {
                    $btn.html('\u786e\u8ba4').unbind('click').show().click(function () {
                        callback.apply(o, []);
                        o.dialog('close');
                    });
                } else {
                    $btn.hide();
                    if (types(callback) === 'object') {
                        ops = callback;
                    }
                }
                var param = projectLib.param.dialogDefaultParam;
                if (ops) {
                    if (ops.buttonText) {
                        $btn.html(ops.buttonText);
                    }
                    if (ops.title) {
                        $title.html(ops.title);
                    }
                    if (ops.confirmText) {
                        $btn.html(ops.confirmText);
                    }
                    if (types(ops.prepare) === 'function') {
                        ops.prepare.apply(o, [msg]);
                    }
                    if (types(ops.param) === 'object') {
                        param = $.extend({}, param, ops.param);
                    }
                }
                $body.html("").html(msg);
                o.dialog(param).dialog('open');
//            o.modal('show');
            };
        }, dateParser = function parseDate(input, format, type) {
            format = format || 'yyyy-MM-dd HH:mm:ss'; // default format
            var parts = input.match(/(\d+)/g),
                i = 0, fmt = {};
            // extract date-part indexes from the format
            format.replace(/(yyyy|dd|MM|HH|mm|ss)/g, function (part) {
                fmt[part] = i++;
            });
            if (type)
                return new Date(parts[fmt['yyyy']], parts[fmt['MM']] - 1, parts[fmt['dd']],parts[fmt['HH']],parts[fmt['mm']],parts[fmt['ss']]);
            else
                return new Date(parts[fmt['yyyy']], parts[fmt['MM']] - 1, parts[fmt['dd']]);
        }, dateFormatter = function (ad) {
            if (types(ad) === 'number') {
                ad = new Date(ad);
            } else if (types(ad) === 'string') {
                ad = dateParser(ad);
                if (/Invalid|NaN/i.test(ad)) {
                    return '';
                }
            } else if (types(ad) === 'date') {

            } else {
                return '';
            }
            return ad.getFullYear() + "-" + prefixZero(ad.getMonth() + 1) + "-" + prefixZero(ad.getDate()) + " ";
        }, dateTimeFormatter = function (ad) {
            if (types(ad) === 'number') {
                ad = new Date(ad);
            } else if (types(ad) === 'string') {
                ad = dateParser(ad);
                if (/Invalid|NaN/i.test(ad)) {
                    return '';
                }
            } else if (types(ad) === 'date') {

            } else {
                return '';
            }
            return ad.getFullYear() + "-" + prefixZero(ad.getMonth() + 1) + "-" + prefixZero(ad.getDate()) + " " + prefixZero(ad.getHours()) + ":" + prefixZero(ad.getMinutes());
        }, timeToNow = function (time) {
            time = time + 0;
            if (!time) {
                return '';
            }
            var now = new Date();
            var cur = now.getTime();
            var ss = cur - time;
            ss = ss / 1000;
            if (ss < 60) {
                return ss + "\u79d2\u524d";
            } else if (ss < 3600) {
                return Math.round(ss / 60) + "\u5206\u949f\u524d";
            } else if (ss < 86400) {
                return Math.round(ss / 3600) + "\u5c0f\u65f6\u524d";
            } else if (ss < 864000) {
                return Math.round(ss / 864000) + "\u5929\u524d";
            } else {
                return dateTimeFormatter(time);
            }
        }, prefixZero = function (i) {
            if (types(i) === 'number')
                return i <= 9 ? '0' + i : i;
            else
                return '0' + i;
        }, len = function (obj, flag) {
            var count = 0;
            if (types(obj) === 'array') {
                count = obj.length;
            } else if (types(obj) === 'string') {
                if (flag) {
                    for (var i = 0, n = obj.length; i < n; i++) {
                        if (obj.charCodeAt(i) > 1024) {
                            count += 2;
                        } else {
                            count += 1;
                        }
                    }
                } else {
                    count = obj.length;
                }
            } else if (types(obj) === 'object') {
                if (!flag) {
                    for (var i in obj) {
                        count++;
                    }
                } else {
                    for (var i in obj) {
                        if (obj[i])
                            count++;
                    }
                }
            }
            return count;
        }, wrapWord = function (msg, n, stuff) {
            if (msg.length < n) {
                return msg;
            } else {
                var ret = '';
                while (msg.length > n) {
                    var m = msg.substr(0, n);
                    msg = msg.substr(n);
                    ret += m + stuff;
                }
                ret += msg;
                return ret;
            }
        }, cookieExtractor = function () {
            var reg = /([a-z1-9_]+)=([^=]+)/i;
            return function (str) {
                if (types(str) === "string") {
                    var cookies = str.split(';'), ret = {};
                    for (var k in cookies) {
                        var cookie = cookies[k],
                            items = reg.exec(cookie);
                        if (items && items.length > 1) {
                            var ss = decodeURI(items[2]);
                            ret[items[1]] = ss;
                        }
                    }
                    return ret;
                }
                return {};
            };
        }, renderBuilder = function () {
            var render = handlebars;
            var risk = ['低', '较低', '中', '较高', '高'];
            render.registerHelper('list', function (context, options) {
                var ret = '<div class="carousel-inner" role="listbox">';
                for (var i = 0, j = context.length; i < j; i++) {
                    var active = "";
                    if (i == 0) {
                        active = "active";
                    }
                    ret = ret + '<div class="item ' + active + '"><img src="' + context[i] + '"></div>';
                }
                return ret + "</div>";
            });
            render.registerHelper('chainSharedBeforeLoc', function (userLoc,chainLength, options) {
                var leftOffset = ((userLoc - 2) / (chainLength - 6) * 22 + 22 + 10)/2;
                return "left:"+leftOffset+"%";

            });
            render.registerHelper('chainSharedBefore', function (userLoc, options) {

                if(userLoc>2)
                    return options.fn(this);
                else
                    return options.inverse(this);

            });

            render.registerHelper('chainSharedAfterLoc', function (userLoc,chainLength, options) {
                var leftOffset = ((userLoc - 2) / (chainLength - 6) * 22 + 22 + 26 + 80)/2;
                return "left:"+leftOffset+"%";

            });
            render.registerHelper('chainSharedAfterNum', function (userLoc,chainLength, options) {
                var leftOffset = chainLength-4-userLoc;
                return leftOffset;

            });
            render.registerHelper('chainSharedBeforeNum', function (userLoc, options) {
                var leftOffset = userLoc-2;
                return leftOffset;

            });
            render.registerHelper('feeBuyRange',function (floor,top ,options){
                var floorFormat=(floor==0||floor==null)?'':(moneyFormatNormal(floor)+'≤');
                var topFormat=(top==0||top==null)?"":('<'+moneyFormatNormal(top));
                return floorFormat+"申购费率" +topFormat;
            } )
            render.registerHelper('moneyFormatNormal' , function (money){
                return moneyFormatNormal(money);
            })
            render.registerHelper('feeBuy',function (amount,unit ,options){
                return amount+unit;
            })
            render.registerHelper('feeTimeRange', function (floor , top, unit ,options){
                 var floorFormat=(floor==0||floor==null)?'':(floor+unit+'≤');
                 var topFormat=(top==0||top==null)?"":('<'+top+unit);
                 return floorFormat+'持有期限'+topFormat;
            })
            render.registerHelper("fundDetail",function (type , param){
                if(type=='fundType')
                {
                    switch(param)
                    {
                        case 1:
                            return "债券型";
                        case 2:
                            return "货币型";
                        case 0:
                            return "股票型";
                        case 3:
                            return "混合型";
                        case 5:
                            return "指数型";
                        default:
                            return "QDII型";
                    }
                }
                else if(type=='fundRisk')
                {
                    switch(param)
                    {
                        case 1:
                            return "较低风险";
                        case 2:
                            return "低风险";
                        case 4:
                            return "高风险";
                        case 3:
                            return "中风险";
                        case 5:
                            return "较高风险";
                    } 
                }
                else if(type=='date')
                {
                    var date=param.toString();
                    var year=date.substr(0,4);
                    var month=date.substring(4,date.length-2);
                    month=(month.length==2)?month:('0'+month);
                    var day=date.substring(date.length-2);
                    return year+'-'+month+'-'+day;
                }
                else if(type=='amount')
                {
                    return moneyFormatNormal(param)+'份';
                }
                else if(type=='property')
                {
                    return moneyFormatNormal(param)+'元';
                }
            })
            render.registerHelper('feeTime',function (amount,unit){
                if(amount==0)
                {
                    return "免手续费";
                }
                else
                {
                    return amount+unit;
                }
            })
            render.registerHelper('feeExists' ,function (array ,options){
                if(!(array.length==0||array.length==null))
                    return options.fn(this);
                else
                    return options.inverse(this);
            })
            render.registerHelper('chainSharedAfter', function (userLoc,chainLength, options) {
                if(userLoc<chainLength - 3)
                    return options.fn(this);
                else
                    return options.inverse(this);

            });
            render.registerHelper('extraTime', function (ss, options) {
                if (ss < 0) {
                    return "已过期";
                }
                if (ss < 60) {
                    return ss + "\u79d2\u524d";
                } else if (ss < 3600) {
                    return Math.round(ss / 60) + "\u5206\u949f";
                } else if (ss < 86400) {
                    return Math.round(ss / 3600) + "\u5c0f\u65f6";
                } else {
                    return Math.round(ss / 86400) + "\u5929";
                }
            });
            render.registerHelper('moneySpan', function (money, options) {
                if (money >= 100000000) {
                    return Math.round(money / 100000000 * 100) / 100 + '<i class="mf">亿</i>';
                } else if (money >= 10000) {
                    return Math.round(money / 10000 * 100) / 100 + '<i class="mf">万</i>';
                } else {
                    return money + '<i class="mf">元</i>';
                }
            });
            render.registerHelper('moneyWan', function (money, options) {
             return Math.round(money / 10000 * 100) / 100;
            });
            render.registerHelper('cuteStar', function (rank, options) {
                var str='';
                var str1='<img src="/resources/app/images/level_star_pre.png"/>';
                var str2='<img src="/resources/app/images/level_star.png"/>';
                for(i=0;i<5;i++){
                    if(rank>i){
                        str=str+str1;
                    }else{
                        str=str+str2;
                    }
                }
                return str;
            });
            render.registerHelper('iconStar', function (rank, options) {
                var str='';
                var str1='<i class="icon-icon_customerlevel"></i>';
                var str2='<i class="icon-icon_user_level"></i>';
                for(i=0;i<5;i++){
                    if(rank>i){
                        str=str+str1;
                    }else{
                        str=str+str2;
                    }
                }
                return str;
            });
            render.registerHelper('chainLoc', function (userLoc,chainLength,type, options) {
                var leftOffset=0;
                if(chainLength>8)
                {
                    switch(type)
                    {
                        case 0:
                        {
                            if(userLoc==chainLength-2)
                            {
                                leftOffset=64;
                            }
                            else if(userLoc==chainLength-3)
                            {
                                leftOffset=54;
                            }
                            else {
                                leftOffset = (userLoc - 2) / (chainLength - 6) * 22 + 22;

                            }
                                // leftOffset=10+(userLoc-1)/(chainLength-3)*52;
                                return "left:"+leftOffset+"%";
                                break;
                            
                        }
                        case 1:
                        {
                            
                            if(userLoc==chainLength-3)
                            {
                                leftOffset=54+13;
                            }
                            else if(userLoc==chainLength-2)
                            {
                                leftOffset=64+13;
                            }
                            else if(userLoc>0)
                            {
                                leftOffset=(userLoc-2)/(chainLength-6)*22+22+13;
                                
                            }
                            else
                            {
                                leftOffset=10;
                            }
                            return "left:"+leftOffset+"%";
                            break;
                            
                        }
                        case 2:
                        {
                            if(userLoc==chainLength-2)
                            {
                                leftOffset=64+26;
                            }
                            else if(userLoc==chainLength-3)
                            {
                                leftOffset=54+26;
                            }
                            else if(userLoc>0)
                            {
                                leftOffset=(userLoc-2)/(chainLength-6)*22+22+26;
                            }
                            
                            else
                            {
                                leftOffset=23;
                            }
                            return "left:"+leftOffset+"%";
                            break;
                        }
                    }
                }
                else
                {
                    leftOffset=(userLoc-1+type)/(chainLength-1)*80+10;
                    return "left:"+leftOffset+"%";
                }
                
            });
            render.registerHelper('timeThree', function (s, options) {
                var   d   =   new   Date(Date.parse(s.replace(/-/g,   "/")));
                h=d.getHours();
                var str='';
                if(h>=15){
                    str='<span class="hot">'+dateFormatter(new Date((d/1000+86400)*1000))+'<em>(您申请时间与所属工作日不在同一天)</em></span>';
                }else{
                    str='<span class="hot">'+dateFormatter(d)+'</span>';
                }
                return str;
            });
            
            render.registerHelper('chainPublisher', function (userLoc, options) {
                if(userLoc>1)
                    return options.fn(this);
                else
                    return options.inverse(this);
            });
            render.registerHelper('chainBuyer', function (userLoc,chainLength, options) {
                if(userLoc<chainLength-2)
                    return options.fn(this);
                else
                    return options.inverse(this);
            });
            render.registerHelper('chainPreviousFinisher', function (userLoc,chainLength, options) {
                if(userLoc<chainLength-3)
                    return options.fn(this);
                else
                    return options.inverse(this);
            });
            render.registerHelper('prop', function (context, options) {
                var ret = "";
                if (context) {
                    ret = context + '="' + context + '"';
                }
                return new render.SafeString(ret);
            });
            render.registerHelper('html', function (context, options) {
                var ret = context || "";
                return new render.SafeString(ret);
            });
            render.registerHelper('intDate', function (context, options) {
                if(context==null||context==''||undefined){
                    return "";
                }
                context=context+"";
                var year=context.substr(0,4);
                var month=context.substr(4,2);
                var day=context.substr(6,2)
                return year+"-"+month+"-"+day;
            });
            /**xqf*/
            render.registerHelper("subtraction",function(v1,v2,options){
                if(v1==undefined||v2==undefined) return 0;
                var sub=v1*1-v2*1;
                return moneyFormatSmale(sub);
            })
            render.registerHelper('dateFormatter', function (context, options) {
                var ret = dateFormatter(context) || "";
                return new render.SafeString(ret);
            });
            render.registerHelper('dateTimeFormatter', function (context, options) {
                var ret = dateTimeFormatter(context) || "";
                return new render.SafeString(ret);
            });
            render.registerHelper('appointPassTime', function (createDate, appointTime, options) {
                var ret = new Date(createDate.replace("-", "/"));
                var passDate = Date.parse(ret) + parseInt(appointTime) * 86400000;
                var result = dateFormatter(new Date(passDate));
                return new render.SafeString(result);

            })
            render.registerHelper('sum', function (c1, c2, options) {
                return c1 * 1 + c2 * 1;
            });
            render.registerHelper('smailsum', function (c1, c2, options) {
                return (c1 * 1 + c2 * 1).toFixed(2);
            });
            render.registerHelper('wanUnit', function (num, options) {
                if (num == undefined || num == "") return 0;
                return (num / 10000).toFixed(0);
            });
            render.registerHelper('isOrNot', function (context, options) {
                return (context) ? "是" : "否";
            });
            render.registerHelper('riskLevel', function (context, options) {

                return risk[parseInt(context) - 1]
            });
            render.registerHelper('checkbox', function (context, option) {
                return (context) ? '<input type="checkbox" checked="checked"  />' : '<input type="checkbox" />';
            });
            render.registerHelper('dateCompare', function (createDate, appointTime, options) {
                var ret = new Date(createDate.replace("-", "/"));
                var passDate = Date.parse(ret) + parseInt(appointTime) * 86400000;
                var now = new Date().getTime();
                console.log(ret + "      " + passDate + "       " + now);
                if (passDate < now) {
                    return options.fn(this);
                }
                else {
                    return options.inverse(this);
                }
            });
            render.registerHelper('iterator', function (context, options) {
                var ret = "", data, count = 0;
                for (var i in context) {
                    if (options.data) {
                        data = render.createFrame(options.data || {});
                        data.innerIndex = i;
                        data.count = count;
                    }
                    ret += options.fn(context[i], {
                        data: data
                    });
                    count++;
                }
                return ret;
            });
            render.registerHelper('test', function (context, options) {
                var vv = options.hash['val'], val, v;
                if (vv.indexOf(',') > 0) {
                    val = vv.split(',');
                    if ($.inArray(context, val) >= 0)
                        return options.fn(this);
                    else
                        return options.inverse(this);
                } else {
                    if (vv === (context + '')) {
                        return options.fn(this);
                    } else {
                        return options.inverse(this);
                    }
                }
            });
            render.registerHelper('userRank', function (context, options) {
                var num=context*1;
                var str="";
                for(var i=0;i<num;i++){
                    str+="<i class='icon-collect-pitchon collected'></i>";
                }
                for(var j=0;j<5-num;j++){
                    str+="<i class='icon-collect-pitchon collect'></i>";
                }
                return str;
            });
            render.registerHelper('substr', function (context, options) {
                var len = options.hash['len'], st = options.hash['start'] || 0;
                return context.toString().substr(st, len);
            });
            render.registerHelper("datafomat", function (context, option) {
                //context.subString(1,10)
                var year = context.substring(2, 4);
                var month = context.substring(5, 7);          //月份
                var date = context.substring(8, 10);
                return year+"-"+month+"-"+date;
            });
            /**update xqf*/
            render.registerHelper("or", function (c1, options) {
                var val1=options.hash['val1'];
                var val2=options.hash['val2'];
                if (c1==val1 || c1==val2) {
                    return options.fn(this);
                } else {
                    return options.inverse(this);
                }
            });


            render.registerHelper("dyxy", function (context, options) {
                if (context * 1 > 0) {
                    return options.fn(this);
                } else {
                    return options.inverse(this);
                }
            })
            render.registerHelper("tnonstandspan", function (v1, v2, options) {
                if ((v1 * 1 - v2 * 1) == 0) {
                    return options.fn(this);
                } else {
                    return options.inverse(this);
                }
            })
            render.registerHelper("tailNo", function (context, option) {
                var tailNo = context;
                return clipTailNumber(tailNo);
            });
            render.registerHelper("testBankId", function (context, option) {
                var currentBankId = context;
                if (currentBankId) {

                }
            });
            render.registerHelper("mjmoney", function (context, option) {

                var money = (context ? context.toString() : 0) * 1;
                return majiemoneyFormatSmale(money)
            });

            render.registerHelper("money", function (context, option) {

                var money = (context ? context.toString() : 0) * 1;
                return moneyFormat(money)
            });
            render.registerHelper("smalemoney", function (context, option) {
                //@xqf
                if (context == undefined || context == "") return 0;
                var money = context.toString() * 1;
                return moneyFormatSmale(money)
            });
            render.registerHelper("wanmoney", function (context, option) {

                if (context == undefined || context == "") return 0;
                var money = context.toString() * 1;
                return moneyFormatWan(money)
            });
            // render.registerHelper("addOne", function (context, option) {

            //     if (context == undefined || context == "") return 0;
            //     var result=parseInt(context)+1;
            //     console.log(result);
            //     return result;
            // });


            render.registerHelper("wan", function (context, option) {

                if (context == undefined || context == "") return 0;
                var money = context.toString() * 1;
                    return Math.round(money / 10000 * 100) / 100;
            });
            render.registerHelper("percent", function (context, option) {

                if (context == undefined || context == "") return 0;
                var percent = context.toString() * 1;
                return Math.round(percent*10000)/100;
            });
            render.registerHelper("sysConstants", function (context, option) {
                if (sysConstants) {
                    var hash = option.hash['name'];
                    console.log(context + '>>>>>>>>>' + hash);
                    return sysConstants['contants'][hash][context];
                } else {
                    return context;
                }
            });
            render.registerHelper("sysConstantsbanks", function (context, context2, option) {
                if (sysConstants) {
                    var hash = option.hash['name'];
                    return sysConstants['banks'][hash][context][context2];
                } else {
                    return context;
                }
            });
            render.registerHelper("doubleFormate", function (context, option) {
                if (context) {
                    //默认保留两位小数
                    var returnval = (context * 1).toFixed(2);
                    return returnval;
                }
                return 0.0;
            });
            render.registerHelper("period", function (context, option) {
                console.log("period:" + context);
                if (context != undefined) {
                    var period = context * 1;
                    if (period == 0)
                        return '天';
                    if (period == 1)
                        return '月';
                    if (period == 2)
                        return '年';
                }
                return '__';
            });

            return render;
        }, render = renderBuilder(), moneyFormat = function (money) {

            return (Math.round(money / 100000000 * 100) / 100) + '亿';

        },
        moneyFormatSmale = function (money) {
            if (money >= 100000000) {
                return Math.round(money / 100000000 * 100) / 100 + '<em class="unit">亿</em>';
            } else if (money >= 10000) {
                return Math.round(money / 10000 * 100) / 100 + '<em class="unit">万</em>';
            } else {
                return money;
            }
        },
        moneyFormatNormal=function(money){
            if (money >= 100000000) {
                return Math.round(money / 100000000 * 100) / 100 + '亿';
            } else if (money >= 10000) {
                return Math.round(money / 10000 * 100) / 100 + '万';
            } else {
                return money;
            }
        },
        majiemoneyFormatSmale = function (money) {
            return Math.round(money / 10000 * 100) / 100 + '';
        },
        moneyFormatWan = function (money) {
            if (money >= 10000) {
                return Math.round(money / 10000 * 100) / 100 + '万元';
            } else {
                return money + '元';
            }
        },
        clipTailNumber = function (str) {
            var arr = str.split("");
            if (arr.length <= 4) {
                return arr.join("");
            } else {
                while (arr.length > 4) {
                    arr.shift();
                }
                return arr.join("");
            }
        },
        scrollTo = function (selector) {
            var $obj;
            if (types(selector) === 'string') {
                $obj = $(selector);
            } else if (types(selector) === 'object') {
                $obj = selector;
            }
            var pos = $obj.position();
            obj.scroll(0, pos.top);
            return $obj;
        }, transToAbsoluteAddr = function (addr) {
            return location.protocol + "//" + location.host + addr;
        }, renderSelector = function (selector, containerSelector, data, addOrReplace) {
            var content;
            if (typeof(selector) === 'string') {
                content = $(selector).html();
            } else if (typeof(selector) === 'object' && typeof(selector.html) == "function") {
                content = selector.html();
            }
            if (content) {
                var tpl = render.compile(content);
                if (data) {
                    var html = tpl(data);
                    var container;
                    if (typeof(containerSelector) === 'string') {
                        container = $(containerSelector);
                    } else if (typeof(containerSelector) === 'object' && typeof(containerSelector.append) == "function") {
                        container = containerSelector;
                    }
                    if (container) {
                        if (addOrReplace)
                            return container.html(html);
                        else
                            return container.append(html);
                    }

                } else {
                    return tpl(data);
                }
            }
            return undefined;
        }, projectLib = {
            'log': logger(0), //done
            'debug': debug, //done
            'ajax': ajax, //done
            'alert': dialogFactory('alert','\u786e\u8ba4'),
            'confirm': dialogFactory('confirm', '\u786e\u8ba4'),
            'majeconfirm':dialogFactory('confirmmaje', '\u786e\u8ba4'),
            'protocol':dialogFactory('protocol','\u786e\u8ba4'),
            'render': render,
            'renderSelector': renderSelector,
            'getType': types,
//        'dataTable': dataTables,
            'scrollTo': scrollTo,
            'transToAbsoluteAddr': transToAbsoluteAddr,
            _time_limit: 1609372800000,
            //'init': init,
//        'widget': {
//            'form': form(),
//            'dataTable': dataTables,
//            'datePicker': datepicker,
//            'autoComplete': autoComplete
//        },
            'param': {
//            datePickerDefaultParam: datePickerDefaultParam,
//            dataTablesDefaultParam: dataTableDefaultParam,
                ajaxDefaultErrorHandler: ajaxErrorHandler,
                dialogDefaultParam: dialogDefaultParam
            },
            'util': {
                'dateFormatter': dateFormatter,
                'dateTimeFormatter': dateTimeFormatter,
                'timeToNow': timeToNow,
                'prefixZero': prefixZero,
                'len': len,
                'cookieEx': cookieExtractor(),
                'wrapWord': wrapWord,
                'money': moneyFormat,
                'smalemoney': moneyFormatSmale
            },
            'config': {}
        };
    //if (window.__ === undefined) {
    //    window.__ = projectLib;
    //} else {
    //    alert("js error");
    //}
    return projectLib;
});
